#ifndef __ETCD_C_API_H__
#define __ETCD_C_API_H__

#ifdef __cplusplus
extern "C" {
#endif

#include <stdint.h>
#include <stdbool.h>

// 定义C语言风格的结构体来表示C++类
typedef struct EtcdClient EtcdClient;
typedef struct EtcdSyncClient EtcdSyncClient;
typedef struct EtcdWatcher EtcdWatcher;
typedef struct EtcdResponse EtcdResponse;
typedef struct EtcdValue EtcdValue;

// EtcdClient相关函数
EtcdClient* etcd_create(const char* etcd_url, const char* load_balancer);
void etcd_destroy(EtcdClient* client);
EtcdResponse* etcd_get(EtcdClient* client, const char* key);
EtcdResponse* etcd_set(EtcdClient* client, const char* key, const char* value, int64_t leaseId);
EtcdResponse* etcd_add(EtcdClient* client, const char* key, const char* value, int64_t leaseId);
EtcdResponse* etcd_modify(EtcdClient* client, const char* key, const char* value, int64_t leaseId);
EtcdResponse* etcd_rm(EtcdClient* client, const char* key);

// EtcdSyncClient相关函数
EtcdSyncClient* etcd_sync_create(const char* etcd_url, const char* load_balancer);
void etcd_sync_destroy(EtcdSyncClient* client);
EtcdResponse* etcd_sync_get(EtcdSyncClient* client, const char* key);
EtcdResponse* etcd_sync_set(EtcdSyncClient* client, const char* key, const char* value, int64_t leaseId);
EtcdResponse* etcd_sync_add(EtcdSyncClient* client, const char* key, const char* value, int64_t leaseId);
EtcdResponse* etcd_sync_modify(EtcdSyncClient* client, const char* key, const char* value, int64_t leaseId);
EtcdResponse* etcd_sync_rm(EtcdSyncClient* client, const char* key);

// EtcdWatcher相关函数
EtcdWatcher* etcd_watcher_create(EtcdClient* client, const char* key, void (*callback)(EtcdResponse*));
void etcd_watcher_destroy(EtcdWatcher* watcher);

// EtcdResponse相关函数
int etcd_response_error_code(EtcdResponse* response);
const char* etcd_response_error_message(EtcdResponse* response);
bool etcd_response_is_ok(EtcdResponse* response);
const char* etcd_response_action(EtcdResponse* response);
int64_t etcd_response_index(EtcdResponse* response);
EtcdValue* etcd_response_value(EtcdResponse* response);
EtcdValue* etcd_response_prev_value(EtcdResponse* response);

// EtcdValue相关函数
const char* etcd_value_key(EtcdValue* value);
const char* etcd_value_as_string(EtcdValue* value);
int64_t etcd_value_created_index(EtcdValue* value);
int64_t etcd_value_modified_index(EtcdValue* value);
int64_t etcd_value_version(EtcdValue* value);
int etcd_value_ttl(EtcdValue* value);
int64_t etcd_value_lease(EtcdValue* value);

#ifdef __cplusplus
}
#endif

#endif // __ETCD_C_API_H__